function bestCharge(selectedItems) {
  var sum = 0;
  var yh1 = 0;
  var yh2 = 0;
  var sz = [];
  var dz = 0 ;
  //alert(selectedItems.length)
  for(var i = 0 ;i<loadAllItems().length;i++){
    for(var j = 0 ;j<selectedItems.length;j++){
      if(loadAllItems()[i].id == selectedItems[j].id ){
        sum += selectedItems[j].num*loadAllItems()[i].price 
        items = {}
        items['id'] = loadAllItems()[i].id;
        items['price'] = loadAllItems()[i].price;
        items['num'] = selectedItems[j].num;
        sz.push(items);
      }
    }
  }

  if(sum >= 30){
    yh1 = sum - parseInt(sum/30)*6
  }else{
    yh1 = sum;
  }

  for(var i = 0 ;i<sz.length;i++){
    if(sz[i].id == loadPromotions()[1].items[0]||sz[i].id == loadPromotions()[1].items[1]){
      dz += (sz[i].price * sz[i].num)/2
    }
    yh2 = sum - dz ;
  }
  if(yh1>yh2){
    return yh2
  }else if (yh2>yh1){
    return yh1
  }else{
    return yh1
  }   
      
   
  
  
  
  
  

}
